var util = require('../../../utils/util.js');
var ajax = require('../../../utils/ajax.js');
var common = require('../../../utils/common.js');
var PageBase = require('../../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
  data: {
    winHei: 0,
    submiting: false,
    logoImg: ''
  },

  onLoad(options) {
    common.initApp({
      loginSuc: () => {
        var logoImg = app.getStoreInfo().logo;
        this.setData({
          logoImg
        })
      }
    });


  },

  onShow() { },
  /**
   * 登录
   */
  _submit: function (evt) {


    var {
      account,
      password
        } = evt.detail.value;

    // var account = 15068888888;
    // var password = '000000';


    var url = "m=store&c=user&a=login";
    var data = {
      mobile: account,
      password
    }

    this.setData({
      submiting: false
    })

    ajax.P({
      url,
      data,
      success: (data) => {
        //debugger;
        if(data.code == 1){
          util.showWarn(data.msg);
          return
        }
        
        var employee_id = data.data.staffid;
        app.setEmployeeid(employee_id);
        app.setEmployeeSid(data.data.sid);
        wx.reLaunch({
          url: '/pages/saler/home/index'
        })
        this.setData({
          submiting: true
        })
      },
      fail: (data) => {
        this.setData({
          submiting: true
        })
      }
    })
  }
}));